home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / USeqPrint-dotty.cpp < prev    next >
Text File  |  1996-07-05  |  21KB  |  915 lines

  1. // USeqPrint.dotty.p 
  2. // d.g.gilbert, 1992 
  3.  
  4. /*
  5.     dotty plot
  6. */
  7.  
  8. #pragma segment DottyPlot
  9.  
  10. CONST
  11.  
  12.     kDottyPlotWindowRSRCID == 1031;
  13.  
  14.  
  15.  
  16. // TDottyPlotDocument -----------------------------------------------
  17.  
  18.  /*---
  19. pascal Str255 numStr( longint anum)
  20. VAR  aStr: Str255;
  21. {
  22.   NumToString( anum, aStr);
  23.     numStr= aStr;
  24. }
  25.  ---*/
  26.  
  27. pascal void windowpt(ptr vSeq, integer nV, hSeq: ptr; integer nH,
  28.                                      integer        nucWindow, nucMatches; boolean doself, allDots,
  29.                                      handle pich)
  30.     EXTERNAL();   //C version*/ /*fills pich handle with points vector
  31.  
  32.  
  33. pascal void TDottyPlotDocument::IDottyPlotDocument(OSType fileType, TDocument parentDoc, 
  34.                     TSeqList        aAlnList; longint startbase, nbases)
  35. VAR
  36.         TFile        aFile;
  37.         
  38.     pascal void CloneIt( TSequence aSeq)  
  39.         //! CloneSeqList: used also in TAlnPasteCommand; make TSeqList method !?
  40.     integer        VAR  aRow;
  41.     {
  42.         aRow= fAlnList->GetEqualItemNo(aSeq);
  43.         aSeq= TSequence(aSeq->Clone());
  44.         fAlnList->AtPut( aRow, aSeq);
  45.     }
  46.   
  47. {
  48.     fDottyPlotView = NULL;
  49.     fParentDoc= parentDoc;
  50.     fAlnList= aAlnList;
  51.     fAlnList->Each(CloneIt);
  52.     fFirstBase= startBase;
  53.     fNBases        = nbases;    
  54.     /*---
  55.     New(aFile);
  56.     aFile->IFile(...);
  57.     aname= parentDoc.name + '.dotplot';
  58.     vol= parentdoc.vol;
  59.     dirid= parentdoc.dirid;
  60.     err= aFile->SpecifyWithTrio( name/vol/dirid);
  61.     ----*/
  62.     aFile= NewFile(fileType, kSAppSig, kUsesDataFork, kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
  63.     IFileBasedDocument( aFile, fileType);
  64.     fSavePrintInfo = FALSE; //was TRUE;
  65. }
  66.  
  67. pascal TFile TDottyPlotDocument::DoMakeFile(itsCommandNumber:CommandNumber); // override 
  68. {
  69.     DoMakeFile= NewFile(fScrapType, gApplication->fCreator, kUsesDataFork, kUsesRsrcFork, 
  70.                                                 !kDataOpen, !kRsrcOpen);
  71. }
  72.  
  73. pascal void TDottyPlotDocument::FreeData(void)
  74. {
  75.     //- if ((fDottyPlotView!=NULL)) fDottyPlotView->Free(); */ /*??
  76.     TObject(fAlnList) = FreeListIfObject(fAlnList);   
  77. }
  78.  
  79.  
  80. pascal void TDottyPlotDocument::Free(void) // override 
  81. {
  82.     FreeData();
  83.     inherited::Free();
  84. }
  85.  
  86.  
  87.  
  88. pascal void TDottyPlotDocument::DoMakeViews(Boolean forPrinting) // override 
  89. VAR
  90.         TWindow        aWindow;
  91.         Point        minSize;
  92.         Point        maxSize;
  93.         vSize     : Vpoint;
  94. {
  95.     aWindow = gViewServer->NewTemplateWindow(kDottyPlotWindowRSRCID, this);
  96.     FailNil(aWindow);
  97.     fDottyPlotWind = TDottyPlotWind(aWindow);
  98.     fDottyPlotWind->IDottyPlotWind();
  99.     
  100.     fDottyPlotView = TDottyPlotView(aWindow->FindSubView('PrVw'));
  101.     FailNil(fDottyPlotView);
  102.  
  103.     fDottyPlotView->fNucWindow= TNumberText(aWindow->FindSubView('nwin'));
  104.     fDottyPlotView->fNucMatches= TNumberText(aWindow->FindSubView('nmat'));
  105.     fDottyPlotView->fAllDots= TCheckBox(aWindow->FindSubView('alld'));
  106.     
  107.     fDottyPlotWind->fRedrawBut= TButton(aWindow->FindSubView('bRDR'));
  108.     fDottyPlotWind->fNucWindow= fDottyPlotView->fNucWindow;
  109.     fDottyPlotWind->fNucMatches= fDottyPlotView->fNucMatches;
  110.     fDottyPlotWind->fAllDots= fDottyPlotView->fAllDots;
  111.     
  112.     fDottyPlotView->fScroller = fDottyPlotView->GetScroller(TRUE);
  113.             //fix so prefview scroll bar shows
  114. /*-    if ((fDottyPlotView->fScroller!=NULL)) 
  115.             fDottyPlotView->fScroller.fScrollLimit.v= 500;*/ 
  116.  
  117.     // get our damn data into view 
  118.     fDottyPlotView->FindDots();
  119.             
  120.     // set window's resize limits so it can't become wider than the DottyPlotview's edge 
  121.     WITH aWindow->fResizeLimits){
  122.         minSize = topLeft;
  123.         maxSize = botRight;
  124.         }
  125.     WITH maxSize)h = Min( 2 + fDottyPlotView->fSize.h + kSBarSizeMinus1, h);
  126.     aWindow->SetResizeLimits(minSize, maxSize);
  127.     vsize.h= maxSize.h;
  128.     vsize.v= maxSize.v;
  129.     if ((fDottyPlotView->fScroller!=NULL)) 
  130.         fDottyPlotView->fScroller->SetScrollLimits(vsize, kDontRedraw);
  131. }
  132.  
  133. pascal void TDottyPlotDocument::UntitledName(Str255 VAR noName) // override 
  134. //called AFTER .Idoc and .MakeViews 
  135. {
  136.     //- noName= Concat(fParentDoc.(*fTitle)^,' Dotplot'); 
  137.     noName= Concat('Dotplot ',fDottyPlotView->fSeqV.fName, 
  138.                                  '-', fDottyPlotView->fSeqH.fName); 
  139.  
  140.     if ((fWindowList != NULL) && (fWindowList.GetSize > 0))         
  141.         TWindow(fWindowList->First())->SetTitle(noName);
  142. }
  143.  
  144.  
  145. /*
  146. TDottyPlotDocument file has the following format:
  147.   Data Fork:
  148.     (a)  kMacdrawHeaderSize (512 bytes) == nulls
  149.     (b)  The rest => PICTure of window
  150.  
  151.  Resource Fork:
  152.     nothing, yet
  153. */
  154.  
  155.  
  156. pascal void TDottyPlotDocument::DoNeedDiskSpace(TFile itsFile,
  157.                                                             long VAR dataForkBytes, rsrcForkBytes)
  158. {
  159.     //)!get Print record requirements 
  160.     //- inherited::DoNeedDiskSpace(dataForkBytes, rsrcForkBytes); 
  161.     
  162.     dataForkBytes = dataForkBytes + kMacdrawHeaderSize  /*+ sizeof window pict */;
  163.     
  164.     /*-- if you really want to know pict size:
  165.     fDottyPlotView->WriteToDeskScrap(); 
  166.     len= fDottyPlotView->GivePasteData( NULL, 'PICT');
  167.     ----*/
  168.     /*---
  169.     rsrcForkBytes = rsrcForkBytes + kRsrcTypeOverhead + kRsrcOverhead + sizeof(DocState);
  170.     ---*/
  171. }
  172.  
  173.  
  174.  
  175. pascal void TDottyPlotDocument::DoRead(aFile:TFile; Boolean forPrinting)
  176. {
  177.     //-- inherited::DoRead(aRefNum, rsrcExists, forPrinting);)!read print info stuff
  178.     // This is a Write-Only document == PICT of output drawing, no reading... ?
  179. }
  180.  
  181.  
  182.  
  183. pascal void TDottyPlotDocument::DoWrite(TFile aFile, Boolean makingCopy)
  184. VAR
  185.         longint        len, count;
  186.         hPict            : handle;
  187.         header        : packed array [1..kMacdrawHeaderSize] of char;
  188.         fi                : FailInfo;
  189.  
  190.     pascal void HdlDoWrite(OSErr error, long message)
  191.     {
  192.         if (hPict != NULL) DisposHandle( hPict);
  193.     }
  194.  
  195. {
  196.     //- inherited::DoWrite(aRefNum, makingCopy);     --)NO write print info stuff
  197.  
  198.     fDottyPlotView->WriteToDeskScrap();
  199.     
  200.     hPict= NewHandle(0);
  201.     CatchFailures(fi, HdlDoWrite);
  202.     len= fDottyPlotView->GivePasteData( hPict, 'PICT');
  203.     if ((len > 0)) {
  204.         fillchar(header, kMacdrawHeaderSize, ((char)(0)));  
  205.         count = kMacdrawHeaderSize;
  206.         FailOSErr( aFile->WriteData( &header, count));
  207.         count= len;
  208.         HLock(hPict);
  209.         FailOSErr( aFile->WriteData( ptr((*hPict)), count));
  210.         HUnlock(hPict);    
  211.         }
  212.     Success(fi);
  213.     DisposHandle( hPict);
  214. }
  215.  
  216.  
  217. // TDottyPlotWind ------------------------- 
  218.  
  219. pascal void TDottyPlotWind::IDottyPlotWind(void)
  220. {
  221.     IPrefWindow();
  222.     fWantSave= TRUE;
  223. }
  224.  
  225. pascal void TDottyPlotWind::SetPrefID(void) /* override */ 
  226. {
  227.     gPrefWindID= kDottyPlotWindowRSRCID; gPrefWindName= 'TDottyPlotWind';
  228. }
  229.  
  230.  
  231. pascal void TDottyPlotWind::DoEvent(EventNumber eventNumber, 
  232.                                             TEventHandler        source; TEvent event) // override 
  233. VAR
  234.         TDottyPlotView        aDottyPlotView;
  235. {
  236.     aDottyPlotView= TDottyPlotDocument(fDocument).fDottyPlotView;
  237.  
  238.     switch (eventNumber) {
  239.  
  240.         mButtonHit: if ((source == fRedrawBut)) {
  241.                 aDottyPlotView->FindDots();
  242.                 aDottyPlotView->ForceRedraw();
  243.                 }            else inherited::DoEvent(eventNumber,source, event); 
  244.  
  245.         otherwise
  246.             inherited::DoEvent(eventNumber,source, event); 
  247.         }
  248. }
  249.  
  250.  
  251.  
  252.  
  253. // TDottyPlotView -------------------------------------
  254.  
  255.  
  256. pascal void TDottyPlotView::FreeData(void)
  257. {
  258.     //!!! NO -- fAlnList is owned by DOC
  259.     /*------
  260.     if ((fAlnList!=NULL)) {
  261.         fAlnList->DeleteAll(); 
  262.         fAlnList->Free(); 
  263.         fAlnList= NULL;
  264.         }
  265.     -----------*/
  266.     fDotsH= DisposeIfHandle( fDotsH);
  267. }
  268.  
  269. pascal void TDottyPlotView::Free(void) // override 
  270. {
  271.     FreeData();
  272.     inherited::Free();
  273. }
  274.  
  275.  
  276. pascal void TDottyPlotView::SetDotRect(void)
  277. //call w/ dotr == pagerect; returns square centered in pagerect
  278. VAR i, maxh, maxv: longint;
  279.         Rect        dotr;
  280.         LoV, nV, HiV,
  281.         longint        LoH, nH, HiH;
  282.         VPoint        minSize;
  283. {
  284.     this->GetQDExtent( dotr);
  285.     fMinSize.h= dotr.right;
  286.     fMinSize.v= dotr.bottom;
  287.     minSize= fMinSize;
  288.     fSeqV->GetSelection( LoV, nV); HiV= LoV + nV;
  289.     fSeqH->GetSelection( LoH, nH); HiH= LoH + nH;
  290.     WITH dotr){
  291.         //make label margins
  292.         left = left + 32;
  293.         right= right - 8;
  294.         i = hiV;
  295.         do {
  296.             right = right - 12; 
  297.             i = i / 10;
  298.         } while (!(i < 1));
  299.         top = top + 100; //margin for titles
  300.         bottom = bottom - 32;
  301.  
  302.         //make plot rect proportional to full dot rect
  303.         maxh = right - left;
  304.         maxv = bottom - top;
  305.         maxh = min(nH, min(maxh, (nH * maxv) / nV));
  306.         maxv = min(nV, min(maxv, (nV * maxh) / nH));
  307.  
  308.         //center in port -- need 6+ lines at top for titles 
  309.         left = left + (right - left - maxh) / 2;
  310.         right = left + maxh;
  311.      //?  top = top + (bottom - top - maxv) / 2; 
  312.         bottom = top + maxv;
  313.         }
  314.     fDotRect= dotr;
  315.  
  316.     if ((fscroller!=NULL)) fScroller->SetScrollLimits(minSize, kDontRedraw);
  317. }    //setDotRect
  318.  
  319.  
  320. pascal void TDottyPlotView::FindDots(void)
  321. VAR
  322.         fullDots, doSelf    : boolean;
  323.         dotsH        : Handle;
  324.         CharsHandle        basesV, basesH;
  325.         longint        startV, startH, nV, nH;
  326. {
  327.     //- Curses(watchCursor); 
  328.     FreeData();
  329.     
  330.     fNucWindowVal= fNucWindow->GetValue();
  331.     fNucMatchesVal= fNucMatches->GetValue();
  332.     fullDots= fAllDots->IsOn();
  333.  
  334.     fDotsH= NewHandle(0);
  335.     FailNIL( fDotsH);
  336.  
  337.     fSeqV= TSequence(fAlnList->First());
  338.     FailNIL( fSeqV);
  339.     Handle(basesV)= fSeqV->fBases;
  340.     fSeqV->GetSelection( startV, nV);
  341.     
  342.             //!? want to handle size > 2 w/ multiple plots 
  343.     if ((fAlnList.GetSize <= 1)) {
  344.         doSelf= TRUE;
  345.         fSeqH= fSeqV;
  346.         basesH= basesV;
  347.         }    else {
  348.         doSelf= FALSE;
  349.         fSeqH= TSequence(fAlnList->At( 2)); 
  350.         FailNIL( fSeqH);
  351.         Handle(basesH)= fSeqH->fBases;
  352.         fSeqH->GetSelection( startH, nH);
  353.         moveHHi( handle(basesH)); HLock(handle(basesH));
  354.         }
  355.     moveHHi( handle(basesV)); HLock(handle(basesV));
  356.  
  357.     if (doSelf)
  358.         windowpt(&(*basesV)^[startV], nV, &(*basesV)^[startV], nV, 
  359.                         fNucWindowVal, fNucMatchesVal, doSelf,
  360.                         fullDots, handle(fDotsH))
  361.     else
  362.         windowpt(&(*basesV)^[startV], nV, &(*basesH)^[startH], nH,
  363.                         fNucWindowVal, fNucMatchesVal, doSelf, 
  364.                         fullDots, handle(fDotsH));
  365.                         
  366.     HUnlock(handle(basesH));
  367.     HUnlock(handle(basesV));
  368.     
  369.     SetDotRect();
  370. }   
  371.  
  372.  
  373.     
  374.  
  375.  
  376. pascal void TDottyPlotView::IDottyPlotView( TDottyPlotDocument itsDocument, Boolean forClipboard)
  377. VAR
  378.         itsSize        : VPoint;
  379.         aHandler    : TDottyPlotHandler;
  380.         sd                : SizeDeterminer;
  381. {
  382.     fDotsH= NULL;
  383.   fNucWindowVal= 0;
  384.     fNucMatchesVal= 0;
  385.     fMinSize= gZeroVPt;
  386.  
  387.     SetVPt(itsSize, kMaxCoord, kMaxCoord);
  388.     if (forClipboard)
  389.         sd = sizeVariable
  390.     else
  391.         sd = sizeFillPages;
  392.     IView(itsDocument, NULL, gZeroVPt, itsSize, sd, sd);
  393.     fScroller = NULL;
  394.     fDottyPlotDocument = itsDocument;
  395.     fFirstBase= fDottyPlotDocument->fFirstBase;  
  396.     fNbases= fDottyPlotDocument->fNbases;  
  397.     fAlnList= fDottyPlotDocument->fAlnList;  
  398.  
  399. #if FALSE                                        //!!! Need to handle this
  400.     if (forClipboard) fWouldMakePICTScrap = TRUE;
  401. #endif
  402.  
  403.     if (!forClipboard) {
  404.         New(aHandler);
  405.         FailNil(aHandler);
  406.         aHandler->IDottyPlotHandler(itsDocument, this, 
  407.                                     !kSquareDots,  
  408.                                   kFixedSize,            // horizontal page size is fixed 
  409.                                   kFixedSize);            // vertical page size is fixed 
  410.         }
  411. }
  412.  
  413.  
  414.  
  415. pascal void TDottyPlotView::Initialize(void) // override 
  416. {
  417.     fDotsH= NULL;
  418.   fNucWindowVal= 0;
  419.     fNucMatchesVal= 0;
  420.     fMinSize= gZeroVPt;
  421.  
  422.     fScroller = NULL;
  423.     fDottyPlotDocument= NULL;
  424.     fFirstBase= 0;
  425.     fNbases= 0;
  426.     fAlnList= NULL;
  427.     inherited::Initialize();
  428. }
  429.  
  430. pascal void TDottyPlotView::DoPostCreate(TDocument itsDocument) // override 
  431. VAR
  432.         TDottyPlotHandler        aHandler;
  433. {
  434.     inherited::DoPostCreate( itsDocument);
  435.     
  436.     fDottyPlotDocument = TDottyPlotDocument(itsDocument);
  437.     fFirstBase= fDottyPlotDocument->fFirstBase;  
  438.     fNbases= fDottyPlotDocument->fNbases;  
  439.     fAlnList= fDottyPlotDocument->fAlnList;  
  440.     
  441.     New(aHandler);
  442.     FailNil(aHandler);
  443.     aHandler->IDottyPlotHandler(itsDocument, this, 
  444.                                 !kSquareDots, // does not have square dots 
  445.                               kFixedSize,                // horizontal page size is fixed 
  446.                               kFixedSize);                // vertical page size is fixed 
  447. }
  448.  
  449.  
  450.  
  451. /*---
  452. CONST
  453.     kTop == 40;
  454.     kNameLeft == 6;
  455.     kNucLeft == 12;
  456.     kFontDescent == 5;
  457.     kIndexOutset == 4;
  458.     kRowLeading == 1;
  459.     kMaxName == 12;
  460.     kBasesPerLine == 40;
  461.     kNucSpace == 2;
  462.     kParagraph == 30;
  463. ---*/
  464.  
  465. pascal void TDottyPlotHandler::IDottyPlotHandler(TDocument itsDocument, TView itsView,
  466.                                             Boolean itsSquareDots, itsHFixedSize, itsVFixedSize)
  467. {
  468.     IStdPrintHandler( itsDocument, itsView,itsSquareDots,itsHFixedSize,itsVFixedSize);
  469.     fAlnList= TDottyPlotView(itsView).fAlnList;
  470. }
  471.  
  472. pascal VCoordinate TDottyPlotHandler::BreakFollowing(VHSelect vhs,
  473.                                          VCoordinate        previousBreak;
  474.                                          Boolean VAR automatic) // override 
  475. //from TStdPrintHandler->BreakFollowing(); Called from fView->DoBreakFollowing(), 
  476. VAR
  477.         VHSelect        orthoVHS;
  478.         VCoordinate        rowTop, maxVpage, endPage, newLoc;
  479.         integer        rowHeight, ngroup, i;
  480.         fi        : FontInfo;
  481.         done    : boolean;
  482. {
  483.  
  484.     BreakFollowing= inherited::BreakFollowing( vhs, previousBreak, automatic);
  485.  
  486. /*******
  487.     orthoVHS = gOrthogonal[vhs];
  488.     automatic = TRUE;
  489.     endPage =  fViewPerPage.vh[orthoVHS];
  490.  
  491.     if ((orthoVHS == v)) {
  492.         /*! we maybe need to calc this for each page, 
  493.             since # of kParagraph spaces can differ per page */
  494.         maxvpage = endPage;
  495.      
  496.         SetPortTextStyle(gPrintNameStyle);
  497.         GetFontInfo(fi);
  498.         rowHeight= fi.ascent+fi.descent+fi.leading;
  499.         rowTop = kTop;
  500.         ngroup = fAlnList->GetSize();
  501.         i= 0;
  502.         do {
  503.             endPage= rowTop;
  504.             i= i+1;
  505.             rowtop = rowtop + rowHeight + kRowLeading;
  506.             if ((i=ngroup)) {
  507.                 rowTop= rowTop + kParagraph;
  508.                 i= 0;
  509.                 }
  510.             done= rowTop >= maxvpage;
  511.         } while (!(done));
  512.         }
  513.         
  514.     newLoc = Min(previousBreak + endPage, fPrintExtent.botRight.vh[orthoVHS]);
  515.     BreakFollowing = newLoc;
  516. *******/
  517. }
  518.  
  519.  
  520.  
  521.  
  522. pascal void TDottyPlotView::Draw(VRect area)    
  523. VAR
  524.     fi    : fontInfo;
  525.     nameHeight, nucHeight,rowHeight    : integer;
  526.     nucLeft, nameLeft, rowTop, saveRowTop, rowLeft, 
  527.     integer        nBases, startBase, basesRemaining;
  528.     integer        chleft, nucwidth ;
  529.     maxNameWid    : integer;
  530.     hMaxBase        : charsHandle;
  531.     
  532. /*************
  533.  
  534.     procedure spaceright( integer i)
  535.     begin
  536.          chleft= chleft + nucwidth; 
  537.          if (i mod 10 == 9) then chleft= chleft + nucwidth;   
  538.     end();
  539.     
  540.     pascal void DrawIndex(void)  
  541.     str255        var  nums;
  542.              i, ws, blockleft    : integer;
  543.     {
  544.     
  545.     // set laserline smaller ...
  546.     // use a custom Index TextStyle (9pt times-italic ?) 
  547.         laserLine( 2, 4);
  548.         chleft= rowLeft;
  549.         blockleft= chleft;
  550.         for i= 0 to nBases-1 do begin
  551.             MoveTo( chleft+kNucSpace, rowtop-kIndexOutset);
  552.             if ((i % 10 == 4)) then begin
  553.                 Line(0,-4);
  554.                 NumToString( i+startBase+1, nums);
  555.                 ws= StringWidth(nums);
  556.                 Move(-ws div 2, -1);
  557.                 DrawString(nums);
  558.                 end
  559.             else
  560.                 Line(0,-2);
  561.         
  562.             if ((i % 10 == 9)) then begin
  563.                 MoveTo( chleft+kNucSpace, rowtop-kIndexOutset);
  564.                 LineTo( blockleft, rowtop-kIndexOutset);
  565.                 blockleft= chleft;
  566.                 end();
  567.             spaceright(i);
  568.             if ((i % 10 == 9)) then 
  569.                 blockleft= chleft;
  570.             end();
  571.     }
  572.         
  573.  
  574.  pascal void GetNameWidth(TSequence aSeq)
  575.  VAR
  576.         myPt        : point;
  577.         aName        : Str63;
  578.  {
  579.     if (aSeq!=NULL) {
  580.         aName= aSeq->fName;
  581.         maxNameWid= max(maxNameWid, StringWidth(aName));
  582.         } 
  583.  }
  584.  
  585.  pascal void DrawNames(TSequence aSeq)
  586.  VAR
  587.          integer        i, rowbot;
  588.         myPt        : point;
  589.         myRect, qdArea    : Rect;
  590.         aName        : Str63;
  591.  {
  592.         rowbot= rowtop + rowHeight;  
  593.         if (aSeq!=NULL) {
  594.           MoveTo( rowleft, rowbot-kFontDescent);
  595.             SetRect( myRect, rowLeft, rowtop, nucLeft, rowBot);
  596.             VRectToRect( area, qdArea);
  597.             if (SectRect( myRect, qdArea, myRect)) {
  598.                 aName= aSeq->fName;
  599.                 maxNameWid= max(maxNameWid, StringWidth(aName));
  600.                 DrawString(aName);
  601.                 }
  602.             } 
  603.         rowtop = rowbot + kRowLeading;
  604.  }
  605.  
  606. **********/
  607.  
  608.  
  609.     pascal void plotDots(void) 
  610.     CONST
  611.         ticsize      == 2;
  612.     VAR
  613.         longint        np, i       ;
  614.         longint        maxv, maxh  ;
  615.         pp          : ^Point;
  616.         pagerect, rdots    : rect;
  617.         longint        LoH, HiH, LoV, HiV, nH, nV;
  618.  
  619.  
  620.     pascal integer maph(longint dotx)
  621.         {
  622.             maph = longint(dotx * maxh) / nH;
  623.         }
  624.  
  625.     pascal integer mapv(longint doty)
  626.         {
  627.             mapv = longint(doty * maxv) / nV;
  628.         }
  629.  
  630.     pascal void getStep(integer w, integer VAR step, z)
  631.         {
  632.             if (w >= 4000) {
  633.                 step = 100; z = 4000;
  634.                 }            else if (w >= 1000) {
  635.                 step = 50; z = 1000;
  636.                 }            else if (w >= 500) {
  637.                 step = 20; z = 500;
  638.                 }            else if (w >= 100) {
  639.                 step = 10;  z = 100;
  640.                 }            else {
  641.                 step = 5; z = 10;
  642.                 }
  643.         }
  644.  
  645.  
  646.     pascal void doTitles(void)
  647.         VAR 
  648.             integer        h, v;
  649.             s, s1    : str255;
  650.             longint        daytime;
  651.             
  652.             pascal void nextLine( str255 s)
  653.             {
  654.                 WITH pagerect)h= (right + left - stringwidth(s)) / 2;
  655.                 v= v + cheight + 4; //!? what is CHeight -- a UPlot funct ?
  656.                 MoveTo(h,v);
  657.                 DrawString(s);
  658.             }
  659.             
  660.         {
  661.             v= pagerect.top;
  662.  
  663.             TextFont(Times); 
  664.             TextSize(14);
  665.             nextline( concat('Dot Plot of ', fSeqV->fName, ' x ', fSeqH->fName));
  666.  
  667.             TextFont(times); 
  668.             TextSize(12);
  669.             np = getHandleSize(handle(fDotsH)) / sizeof(point);
  670.             nextline( concat('Base Window: ',numStr(fNucWindowVal),
  671.                                  '  Stringency: ',numStr(fNucMatchesVal),
  672.                                  '  Points: ',numStr(np)) );
  673.             getDateTime( daytime);
  674.             iuDateString( daytime, abbrevDate, s);
  675.             iuTimeString( daytime, FALSE,  s1);
  676.             nextline( concat(s,'  ',s1));                
  677.             
  678.             //horizontal axis 
  679.             s= concat( fSeqH->fName, '  (',numStr(LoH),' to ',numStr(HiH-1),')');
  680.             moveto((rdots.left + rdots.right - stringwidth(s)) / 2, rdots.bottom + 20);
  681.             drawstring(s);
  682.  
  683.             //vertical axis 
  684.             s= concat( fSeqV->fName, '  (',numStr(LoV),' to ',numStr(HiV-1),')');
  685.             h = rdots.left - 14;
  686.             v = (rdots.bottom + rdots.top) / 2;
  687.             textPicDraw(h, v, 270, s);
  688.         }                         
  689.         
  690.         
  691.         pascal void doTicLabels(void)
  692.         VAR
  693.             integer        h, v, k, k1, i, z, step;
  694.             str255        s           ;
  695.         {
  696.             TextFont(times); 
  697.             TextSize(10);
  698.             //horizontal
  699.             getStep(nH, step, z);
  700.             k = (LoH / z) * z; k1= 0;
  701.             do {
  702.                 if (k >= LoH) {
  703.                     h = maph(k - LoH);
  704.                     moveto(rdots.left + h,  rdots.bottom);
  705.                     if k1 mod 10 == 0 then line(0, 5) 
  706.                     else line(0, 2);
  707.                     moveto(rdots.left + h,  rdots.top);
  708.                     if k1 mod 10 == 0 then begin
  709.                         numToString(k, s);
  710.                         line(0, -5);
  711.                         move(-(stringwidth(s) / 2), -3);
  712.                         drawstring(s);
  713.                         end
  714.                     else 
  715.                         line(0, -2);
  716.                     }
  717.                 k = k + step; k1= k1+1;
  718.             } while (!((k > HiH)));
  719.  
  720.             //verticals 
  721.             getStep(nV, step, z);
  722.             k = (LoV / z) * z; k1= 0;
  723.             do {
  724.                 if (k >= LoV) {
  725.                     v = mapv(k - LoV);
  726.                     moveto(rdots.left, rdots.bottom - v);
  727.                     if k1 mod 10 == 0 then line( -5, 0)
  728.                     else line(-2, 0);
  729.                     moveto(rdots.right, rdots.bottom - v);
  730.                     if k1 mod 10 == 0 then begin
  731.                         numToString(k, s);
  732.                         line( 5, 0);
  733.                         move( 4, 3);
  734.                         drawstring(s);
  735.                         end
  736.                     else
  737.                         line(2, 0);
  738.                     }
  739.                 k = k + step; k1= k1+1;
  740.             } while (!((k > HiV)));
  741.         }    //doTicLabels
  742.  
  743.     {
  744.         //- Handle(basesH)= fSeqH->fBases; 
  745.         fSeqH->GetSelection( LoH, nH);
  746.         HiH= LoH + nH;
  747.         fSeqV->GetSelection( LoV, nV);
  748.         HiV= LoV + nV;
  749.         
  750.         this->GetQDExtent(pagerect); 
  751.         rdots= fDotRect;        
  752.         with rdots do begin
  753.             maxh= right - left;
  754.             maxv= bottom- top;
  755.             end();
  756.             
  757.         beginPicGroup();
  758.         
  759.         beginPicGroup();
  760.         doTitles();
  761.         endPicGroup();
  762.  
  763.         beginPicGroup();
  764.         framerect(rdots);
  765.         doTicLabels();
  766.         endPicGroup();
  767.  
  768.         beginPicGroup();
  769.         laserLine(1, 2);  //! note 1,3 or smaller doesn't work on DEC ScriptPrinter 
  770.         moveHHi(handle(fDotsH));
  771.         hlock(handle(fDotsH));
  772.         np = getHandleSize(handle(fDotsH)) / sizeof(point);
  773.         Ptr(pp) = (*fDotsH);
  774.         FOR i = 0 TO np - 1){
  775.             /*--------- (for subrange plots)
  776.             if (pp->h>= fLoH1 - LoH) and (pp->h <= fHiH1-LoH)
  777.              and (pp->v >= fLoV1 - LoV) and (pp->v <= fHiV1-LoV)
  778.                 then
  779.             ---------*/
  780.                 {
  781.                 moveto(rdots.left + maph(pp->h), rdots.top + mapv(pp->v));
  782.                 line(0, 0);
  783.                 }
  784.             longint(pp) = longint(pp) + sizeof(point);
  785.             }
  786.         hunlock(handle(fDotsH));
  787.         endPicGroup();
  788.         
  789.         endPicGroup();
  790.         
  791.     }  //plotDots
  792.  
  793.  
  794. {
  795.  
  796.     inherited::Draw(area);
  797.  
  798.     SetPortTextStyle(gPrintNucStyle);
  799.     
  800.     PlotDots();
  801.     
  802. /********
  803.     //! do MacDraw grouping messages 
  804.     nameLeft= kNameLeft;
  805.  
  806.     SetPortTextStyle(gPrintNameStyle);
  807.     GetFontInfo(fi);
  808.     nameHeight= fi.ascent+fi.descent+fi.leading;
  809.     maxNameWid= 0;
  810.     fAlnList->Each(GetNameWidth);
  811.     //- nucLeft = nameLeft + kMaxName*charWidth('W') + kNucLeft;
  812.     nucLeft = nameLeft + maxNameWid + kNucLeft;  //???
  813.  
  814.     SetPortTextStyle(gPrintNucStyle);
  815.     nucwidth= CharWidth('G')+kNucSpace;
  816.     nucHeight= fi.ascent+fi.descent+fi.leading;
  817.     rowHeight= /*kRowLeading +*/ max( nucHeight, nameHeight);
  818.     
  819.     rowTop    = kTop;
  820.     startBase= fFirstBase;
  821.     basesRemaining= fNBases;
  822.     if (basesRemaining < 1) 
  823.      if ((fAlnList!=NULL) && (fAlnList.GetSize>0))
  824.         basesRemaining= TSequence(fAlnList->First()).fLength;
  825.     while (basesRemaining > 0)){
  826.     
  827.         nBases= min(kBasesPerLine, basesRemaining);
  828.  
  829.         beginPicGroup();
  830.         rowLeft= nucLeft;
  831.         SetPortTextStyle(gPrintNameStyle);
  832.         DrawIndex();
  833.         endPicGroup();
  834.  
  835.         beginPicGroup();
  836.         rowLeft=    nameLeft;  
  837.         saveRowTop= rowTop;
  838.         SetPortTextStyle(gPrintNameStyle);
  839.         fAlnList->Each(DrawNames);
  840.         endPicGroup();
  841.     
  842.         beginPicGroup();
  843.         rowTop= saveRowTop; 
  844.         rowLeft= nucLeft;
  845.         SetPortTextStyle(gPrintNucStyle);
  846.         fAlnList->Each(DrawNucs);
  847.         endPicGroup();
  848.         
  849.         startBase= startBase + nBases;
  850.         basesRemaining= basesRemaining - nBases;
  851.         rowTop= rowTop + kParagraph;
  852.         }
  853.         
  854.     fMinSize.h= nucLeft + chleft + 40;
  855.     fMinSize.v= rowTop + 40;
  856. *******/
  857. }
  858.  
  859.  
  860.  
  861. pascal void TDottyPlotView::CalcMinFrame(VRect VAR minFrame)
  862. VAR
  863.     nb    : integer;
  864.     TScroller        aScroller;
  865.     VPoint        aPt;
  866. {
  867.     inherited::CalcMinFrame( minFrame);
  868.     minFrame.right= max(minFrame.right, fMinSize.h);
  869.     minFrame.bottom= max(minFrame.bottom, fMinSize.v);
  870.     aScroller= GetScroller(TRUE);
  871.     SetVPt( aPt, minFrame.right, minFrame.bottom);
  872.     if ((ascroller!=NULL)) aScroller->SetScrollLimits(aPt, kDontRedraw);
  873. }
  874.  
  875.  
  876.  
  877.  
  878. pascal void TDottyPlotView::DoMenuCommand(CommandNumber aCommandNumber) // override 
  879. {
  880.     switch (aCommandNumber) {
  881.         cCopy: {
  882.                 this->WriteToDeskScrap(); 
  883.                 gClipboardMgr->CheckDeskScrap(); //! this notifies app of changed scrap 
  884.                 }
  885.         otherwise
  886.             inherited::DoMenuCommand(aCommandNumber);
  887.         }
  888. }
  889.  
  890.  
  891.  
  892. pascal void TDottyPlotView::DoSetupMenus(void)
  893.     {
  894.         short        i;
  895.         Boolean        anySelection;
  896.         Boolean        haveMemory;
  897.         MenuHandle        aMenuHandle;
  898.         short        item;
  899.         Str255        itemName;
  900.  
  901.  
  902.     inherited::DoSetupMenus();
  903.  
  904.     anySelection = FALSE;
  905.     haveMemory = !MemSpaceIsLow;
  906.  
  907.     Enable(cCopy, TRUE && haveMemory);
  908. /*----    
  909.     Enable(cCut, anySelection && haveMemory);
  910.     if (haveMemory) CanPaste(kPrintClipType);
  911.     Enable(cClear, anySelection);
  912. -------*/
  913. }             
  914.  
  915.